package cn.kuick.match2.test2;

public class LongestSub {

	public static boolean isMatch(String expr, int i) {
		if (i < expr.length() - 1) {
			if (expr.charAt(i) == '(' && expr.charAt(i + 1) == ')') {
				return true;
			}
		}
		
		return false;
	}
	
	public static long eval(String expr) {
		int max = 0;
		int fcout = 0;
		
		for(int i=0; i<expr.length(); i++) {
			if (isMatch(expr, i)) {
				i++;
				fcout++;
			} else {
				max = Math.max(max, fcout*2);
				fcout = 0;
			}
		}
		
		max = Math.max(max, fcout*2);
		
		return max;
	}
	
	public static void main(String[] args) {
		long output = eval("())(()()))");
		System.out.println(output);
		
		long output2 = eval("))()()())(()");
		System.out.println(output2);
		
		long output3 = eval(")()(()(())()");
		System.out.println(output3);
	}
	
}
